package com.hnkywl.sts.entity.htgl;

import com.hnkywl.sts.entity.base.Sjzdz;
import com.hnkywl.sts.entity.cggl.Cgd;
import com.hnkywl.sts.entity.organ.Nbbm;
import com.hnkywl.sts.entity.organ.Nbgs;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：采购合同
 * 包:        com.hnkywl.sts.entity.htgl
 * 类描述:    采购合同
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Entity
@Where(clause = "deleted!='1'")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("cght")
public class Cght extends Ht {
    /**
     * 采购类型（统配采购合同，直达到货采购合同，保供合同）
     */
    private String cglx;

    /**
     * 采购单
     */
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cght", targetEntity = Cgd.class)
    private List<Cgd> cgdList;


    /**
     * 统筹公司
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "TCGS_ID")
    private Nbgs tcgs;

    //付款时间
    private Date fksj;

    /**
     * 统筹部门
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "TCBM_ID")
    private Nbbm tcbm;


    /**
     * 关联直达到货的销售合同
     */

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "zddhcght", targetEntity = Xsht.class)
    private List<Xsht> zddhxshtList;


    /**
     * 招标比价    1 比价  2 招标
     */
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "SJZDZ_ZBBJ_ID")
//    @NotFound(action= NotFoundAction.IGNORE)
    private Long zbbj;

    /**
     * 资金合同标志
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SJZDZ_ZJHTBZ_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Sjzdz zjhtbz;

    /**
     * 常规寄售
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SJZDZ_CGJS_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Sjzdz cgjs;

    /**
     * 导入方式
     */
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "SJZDZ_DRFS_ID")
//    private Sjzdz drfs;

    /**
     * 导入时间
     */
    private Date drsj;

    @Formula("(select  NVL(sum(t.SBSL),0) from T_BIZ_HTMX t where t.HT_ID=ID and t.deleted!=1)")
    private Double sbsl;
    //含税总额
    @Formula("(select  NVL(sum(t.SBSL*t.HSJ),0) from T_BIZ_HTMX t where t.HT_ID=ID and t.deleted!=1)")
    private Double hsze;

    @Formula("(select NVL(sum(a.SBSL),0) from T_BIZ_CGD t left join T_BIZ_CGDMX a on a.CGD_ID=t.ID where t.CGHT_ID=ID and t.ZT='ytj' and t.DELETED!=1)")
    private Double wlyl;

//    @Formula("(select a.htbm from T_BIZ_HT a where ID=a.ZDDHCGHT_ID and a.deleted!=1)")
//    private String xshtbm;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = Bgfkfs.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "BGHT_ID")
    private List<Bgfkfs> bgFkfs;


    /**
     * 融资类型
     */
    private RZLX rzlx;

    public RZLX getRzlx() {
        return rzlx;
    }

    public void setRzlx(RZLX rzlx) {
        this.rzlx = rzlx;
    }

    public enum RZLX {
        //0、代订货 1、商贸银 2、保兑仓
        DDH("代订货"), SMY("商贸银"), BDC("保兑仓");

        private RZLX(String mc) {
            this.mc = mc;
        }

        private String mc;

        public String getMc() {
            return mc;
        }

        public static Map<String, String> getRzlxList() {
            Map<String, String> map = new LinkedHashMap<String, String>();
            RZLX[] temp = RZLX.values();
            for (RZLX aTemp : temp) map.put(aTemp.toString(), aTemp.getMc());
            return map;
        }
    }

    //上传仓储系统状态0= 未上传仓储系统、1表示上上传成功2、表示上传失败
    private Integer ckzt = 0;


    public Double getWlyl() {
        return wlyl;
    }

    public void setWlyl(Double wlyl) {
        this.wlyl = wlyl;
    }

    public Integer getCkZt() {
        return ckzt;
    }

    public void setCkZt(Integer ckZt) {
        this.ckzt = ckZt;
    }

    public Double getHsze() {
        return hsze;
    }

    public void setHsze(Double hsze) {
        this.hsze = hsze;
    }

    public Date getFksj() {
        return fksj;
    }

    public void setFksj(Date fksj) {
        this.fksj = fksj;
    }

    public String getCglx() {
        return cglx;
    }

    public void setCglx(String cglx) {
        this.cglx = cglx;
    }

    public List<Cgd> getCgdList() {
        return cgdList;
    }

    public void setCgdList(List<Cgd> cgdList) {
        this.cgdList = cgdList;
    }

    public Nbgs getTcgs() {
        return tcgs;
    }

    public void setTcgs(Nbgs tcgs) {
        this.tcgs = tcgs;
    }

    public Nbbm getTcbm() {
        return tcbm;
    }

    public void setTcbm(Nbbm tcbm) {
        this.tcbm = tcbm;
    }

    public Long getZbbj() {
        return zbbj;
    }

    public void setZbbj(Long zbbj) {
        this.zbbj = zbbj;
    }

    public Sjzdz getZjhtbz() {
        return zjhtbz;
    }

    public void setZjhtbz(Sjzdz zjhtbz) {
        this.zjhtbz = zjhtbz;
    }

    public Sjzdz getCgjs() {
        return cgjs;
    }

    public void setCgjs(Sjzdz cgjs) {
        this.cgjs = cgjs;
    }

//    public Sjzdz getDrfs() {
//        return drfs;
//    }
//
//    public void setDrfs(Sjzdz drfs) {
//        this.drfs = drfs;
//    }

    public Date getDrsj() {
        return drsj;
    }

    public void setDrsj(Date drsj) {
        this.drsj = drsj;
    }

    public List<Xsht> getZddhxshtList() {
        return zddhxshtList;
    }

    public void setZddhxshtList(List<Xsht> zddhxshtList) {
        this.zddhxshtList = zddhxshtList;
    }

    public Double getSbsl() {
        return sbsl;
    }

    public void setSbsl(Double sbsl) {
        this.sbsl = sbsl;
    }

    public List<Bgfkfs> getBgFkfs() {
        return bgFkfs;
    }

    public void setBgFkfs(List<Bgfkfs> bgFkfs) {
        this.bgFkfs = bgFkfs;
    }
}
